#include <iostream>
#include <string>

#include <assert.h>
#include <pthread.h>
#include <unistd.h>

using namespace std;

// 新线程
void *start_routine(void *arg)
{
    // string name = (const char *)arg;
    // 安全的进行强制类型转化
    string name = static_cast<const char *>(arg);
    while (true)
    {
        cout << "new thread creat success, name:" << name << endl;
        sleep(1);
        int *p = nullptr;
        *p = 1;
    }
}

int main()
{
    pthread_t id;
    pthread_create(&id, nullptr, start_routine, (void *)"thread new");

    // 主线程
    while (true)
    {
        cout << "main thread" << endl;
        sleep(1);
    }
    return 0;
}